package com.ybkj.o2o.zhuanche.service.impl;

import com.ybkj.o2o.zhuanche.common.query.CarTypeQuery;
import com.ybkj.o2o.zhuanche.entity.ServiceType;
import com.ybkj.o2o.zhuanche.entity.ServiceTypeCriteria;
import com.ybkj.o2o.zhuanche.entity.ServiceTypeCriteria.Criteria;
import com.ybkj.o2o.zhuanche.mapper.BaseMapper;
import com.ybkj.o2o.zhuanche.mapper.ServiceTypeMapper;
import com.ybkj.o2o.zhuanche.service.ServiceTypeService;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DefaultServiceTypeService extends
    AbstractBaseService<ServiceType, ServiceTypeCriteria, Long> implements ServiceTypeService {

  @Autowired
  private ServiceTypeMapper serviceTypeMapper;

  @Override
  public BaseMapper<ServiceType, ServiceTypeCriteria, Long> getMapper() {
    return serviceTypeMapper;
  }

  @Override
  public int insert(ServiceType serviceType) {
    serviceType.setCreated(new Date());
    serviceType.setUpdated(new Date());
    return super.insert(serviceType);
  }

  @Override
  public ServiceType findByServiceTypeId(Long serviceTypeId, String appKey) {
    return serviceTypeMapper.findByServiceTypeId(serviceTypeId,appKey);
  }

  @Override
  public List<ServiceType> findByCarTypeId(Long carTypeId, String appKey) {
    return serviceTypeMapper.findByCarTypeId(carTypeId,appKey);
  }

  @Override
  public int deleteById(Long id, String appKey) {
    return serviceTypeMapper.deleteById(id,appKey);
  }

  @Override
  public List<ServiceType> findByServiceType(String serviceType, String appKey) {
    return serviceTypeMapper.findByServiceType(serviceType,appKey);
  }

  @Override
  public List<ServiceType> findByCompanyName(
      String companyName, RowBounds rowBounds, String appKey) {
    ServiceTypeCriteria example = new ServiceTypeCriteria();
    Criteria criteria = example.createCriteria();
    criteria.andAppKeyEqualTo(appKey);
    if (rowBounds != null) {
      return serviceTypeMapper.selectByExampleWithRowbounds(example, rowBounds);
    } else {
      return serviceTypeMapper.selectByExample(example);
    }
  }

  @Override
  public Long countByCompanyName(String companyName, String appKey) {
    ServiceTypeCriteria example = new ServiceTypeCriteria();
    Criteria criteria = example.createCriteria();
    criteria.andAppKeyEqualTo(appKey);
    return serviceTypeMapper.countByExample(example);
  }

  @Override
  public ServiceType findByNameAndCarTypeId(
      Long carTypeId, Long companyId, String name, String appKey) {
    return serviceTypeMapper.findByNameAndCarTypeId(carTypeId,companyId,name,appKey);
  }

  @Override
  public List<ServiceType> findByCarTypeCompanyId(Long carTypeCompanyId, String appKey) {
    return serviceTypeMapper.findByCarTypeCompanyId(carTypeCompanyId,appKey);
  }

  @Override
  public ServiceType findByCarTypeCompanyIdAndServiceType(Long carTypeCompanyId,
      String serviceType, String appKey) {
    return serviceTypeMapper.findByCarTypeCompanyIdAndServiceType(
        carTypeCompanyId,serviceType,appKey);
  }

  @Override
  public List<ServiceType> findByCarTypeIdAndCarTypeCompanyId(Long carTypeId,
      Long carTypeCompanyId, String appKey) {
    return serviceTypeMapper.findByCarTypeIdAndCarTypeCompanyId(carTypeId,carTypeCompanyId,appKey);
  }

  @Override
  public ServiceType queryServiceType(CarTypeQuery carTypeQuery) {
    
    return serviceTypeMapper.queryServiceType(carTypeQuery);
  }

  @Override
  public Long deleteByCarTypeId(Long carTypeId, String appKey) {
    return serviceTypeMapper.deleteByCarTypeId(carTypeId,appKey);
  }

}
